#ifndef KFS_H_
# define KFS_H_

# define FD_MAX 64

typedef struct
{
    t_uint32 magic_number;
    char file_system_name[32];
    t_sint32 creation_timestamp;
    t_uint32 blocks_count;
    t_uint32 i_nodes_count;
    t_uint32 first_i_node_block_index;
    t_uint32 checksum;
} __attribute__ ((packed)) t_superblock;

typedef struct
{
    t_uint32 i_number;
    char filename[32];
    t_uint32 file_size;
    t_uint32 i_node_block_index;
    t_uint32 block_counts;
    t_uint32 next_i_node_block_index;
    t_uint32 direct_blocks_count;
    t_uint32 indirect_blocks_count;
    t_uint32 direct_blocks_indexes[10];
    t_uint32 indirect_blocks_indexes[16];
    t_uint32 checksum;
} __attribute__ ((packed)) t_i_node;

typedef struct
{
    t_uint32 indirect_block_index;
    t_uint32 blocks_count;
    t_uint32 data_blocks_indexes[16];
    t_uint32 checksum;
} __attribute__ ((packed)) t_indirect_block;

typedef struct
{
    t_uint32 data_block_index;
    t_uint32 block_usage;
    t_uint32 checksum;
    char data[4096 - 3 * 4];
} __attribute__ ((packed)) t_data_block;

typedef struct
{
    int id;
    t_i_node* i_node;
    t_uint32 curr_indirect_i;
    t_uint32 curr_data_block_i;
    t_indirect_block* curr_indirect;
    t_data_block* curr_data_block;
    t_uint32 pos;
    char* cursor;
} t_file_descriptor;

void kfs_init(unsigned int super_addr);

#endif
